//
//  RecommendUserRequest.m
//  collection
//
//  Created by Jing on 4/23/12.
//  Copyright (c) 2012 Tsinghua University. All rights reserved.
//

#import "RecommendUserRequest.h"

@implementation RecommendUserRequest

- (void)initParams {
    
    self.descriptionName = @"user.recommend";
    
    RecommendUserRequestData* requestData = [[RecommendUserRequestData alloc] init];
    self.request = requestData;
    [requestData release];
    
    RecommendUserResponse* response = [[RecommendUserResponse alloc] init];
    self.response = response;
    [response release];
}

- (NSString*)buildRequestURL {
    
    RecommendUserRequestData* requestData = (RecommendUserRequestData*)self.request;
    
    NSString* requestContent = [NSString stringWithFormat:@"&num=%d", requestData.recommendNum];
    
    return requestContent;
}

- (void)parseResponse:(NSObject *)data {
    
    RecommendUserResponse* response = (RecommendUserResponse*)self.response;
    
    // users
    NSArray* rawUserArray = (NSArray*)data;
    if (rawUserArray != nil) {
        
        NSMutableArray* userArray = [[NSMutableArray alloc] initWithCapacity:1];
        for (NSDictionary* userData in rawUserArray) {
            UserInfo* user = [self parseOneUser:userData];
            if (user != nil) {
                [userArray addObject:user];
                [user release];
            }
        }
        
        response.userList = userArray;
        [userArray release];
    }
}

@end
